home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11837 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.0 KB  |  44 lines

  1. Path: news.mindspring.com!usenet
  2. From: rroberts@mindspring.com (Ryan Roberts)
  3. Newsgroups: comp.lang.c++
  4. Subject: Random number question....
  5. Date: Sat, 16 Mar 1996 15:31:16 GMT
  6. Organization: MindSpring Enterprises
  7. Message-ID: <4iemrd$iap@firebrick.mindspring.com>
  8. NNTP-Posting-Host: rroberts.mindspring.com
  9. X-Newsreader: Forte Free Agent 1.0.82
  10.  
  11. Hello all,  I'm _just_ getting starting programming and have bought
  12. all the books,  but still have a question.  Look at this code:
  13.  
  14. #include <iostream.h>
  15. #include <stdlib.h>
  16. #include <stdio.h>
  17.  
  18. main()
  19. {
  20.     int num;
  21.     randomize;
  22.     num = (rand() % 5 + 1);
  23.     if (num==0) cout << "Random Number 1\n";
  24.     if (num==1) cout << "Random Number 2\n";
  25.     //etc.... down to Random Five    
  26.     return 0;
  27. }
  28.  
  29. When I run this code it will disply more than one random number
  30. between 0-5.  It display's like:
  31. Random Number 1
  32. Random Number 2
  33. etc....
  34.  
  35. Can some tell me how to generate _one_ random number
  36. between 0-5 and it disaply one the string assoicated with that
  37. random number?
  38.  
  39. Thanks!!
  40.  
  41. rroberts@mindspring.com
  42.  
  43.  
  44.